CREATE OR REPLACE FUNCTION func_add_column() RETURNS void AS $$
DECLARE
    VCOUNT  INTEGER := 0;
BEGIN
  SELECT count(*) into VCOUNT FROM pg_attribute WHERE attrelid='<SCHEMA>.synchronization_error'::REGCLASS AND attname = 'ENTITY_NATURAL_KEY';
  IF VCOUNT = 0 THEN
    ALTER TABLE <SCHEMA>.SYNCHRONIZATION_ERROR ADD ENTITY_NATURAL_KEY VARCHAR(255);
  END IF;
  RETURN;
END;
$$ LANGUAGE plpgsql;
SELECT func_add_column();
DROP FUNCTION func_add_column();

COMMENT ON COLUMN <SCHEMA>.SYNCHRONIZATION_ERROR.ENTITY_NATURAL_KEY is 'ARMAZENA A NATURAL KEY DA ENTIDADE SINCRONIZADA';
